<template>
  <div class="main">
    <h3>搜索的歌曲</h3>
    <ul class="list">
      <li
        v-for="(v, k) in songList"
        :key="v.id"
        :class="{ currentStyle: v.isOn }"
        @mouseenter="v.isOn = true"
        @mouseleave="v.isOn = false"
        @click="$router.push('/Detail?id=' + v.id)"
      >
        <span class="xuhao">{{ k + 1 }}</span>
        <span class="songName">{{ v.name }}</span>
        <span>{{ v.artists[0].name }}</span>
      </li>
    </ul>
  </div>
</template>

<script>
import req from '../untils/request'
export default {
  data() {
    return {
      songList: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      const { code, result } = await req.get('/search', {
        keywords: this.$route.query.inpName
      })
      if (code === 200) {
        result.songs.forEach(v => {
          v.isOn = false
        })
        this.songList = result.songs
        console.log(this.songList)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.main {
  width: 1200px;
  margin: 0 auto;
  h3 {
    font-size: 18px;
  }
  .list {
    list-style: none;
    padding: 10px;

    .currentStyle {
      background-color: rgb(187, 184, 184) !important;
    }
    li {
      display: flex;
      font-size: 18px;
      line-height: 55px;
      padding-left: 20px;
      flex-wrap: nowrap;
      cursor: pointer;

      &:nth-child(2n + 1) {
        background-color: #f7f7f7;
      }
    }
  }
}
.songName {
  width: 750px;
  margin: 0 100px;
}
.xuhao {
  width: 30px;
}
</style>
